import java.util.Collection;
import java.util.Iterator;


public class Portefeuille implements Collection<CarteBancaire> {
	
	private CarteBancaire[] portefeuille;
	private int nbrCartes;
	
	public Portefeuille() {
		this.portefeuille = new CarteBancaire[5];
		this.nbrCartes = 0;
	}

	@Override
	public boolean add(CarteBancaire e) {
		if(e == null)
			return false;
		if(nbrCartes==portefeuille.length){
			CarteBancaire[] temp = new CarteBancaire[portefeuille.length*2];
			for(int i = 0; i < portefeuille.length; i++){
				temp[i]=portefeuille[i];
			}
			portefeuille=temp;
		}
		portefeuille[nbrCartes] = e;
		nbrCartes++;
		return true;
	}

	@Override
	public boolean addAll(Collection<? extends CarteBancaire> c) throws UnsupportedOperationException{
		throw new UnsupportedOperationException();
	}

	@Override
	public void clear() {
		nbrCartes = 0;
	}

	@Override
	public boolean contains(Object o) {
		if(o == null)
			return false;
		if(!(o instanceof CarteBancaire))
			return false;
		CarteBancaire carte = (CarteBancaire) o;
		for(int i = 0; i < nbrCartes; i++){
			if(portefeuille[i].getNumero()==carte.getNumero())
				return true;
		}
		return false;
	}

	@Override
	public boolean containsAll(Collection<?> c) throws UnsupportedOperationException{
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean isEmpty() {
		return nbrCartes==0;
	}

	@Override
	public Iterator<CarteBancaire> iterator() throws UnsupportedOperationException{
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean remove(Object o) {
		if(o == null)
			return false;
		if(!(o instanceof CarteBancaire))
			return false;
		if(nbrCartes==0)
			return false;
		CarteBancaire carte = (CarteBancaire) o;
		for(int i = 0; i < nbrCartes; i++){
			if(portefeuille[i].getNumero()==carte.getNumero()){
				portefeuille[i]=portefeuille[nbrCartes-1];
				nbrCartes--;
			}
		}
		return true;
	}

	@Override
	public boolean removeAll(Collection<?> c) throws UnsupportedOperationException{
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean retainAll(Collection<?> c) throws UnsupportedOperationException{
		throw new UnsupportedOperationException();
	}

	@Override
	public int size() {
		return nbrCartes;
	}

	@Override
	public Object[] toArray() throws UnsupportedOperationException{
		throw new UnsupportedOperationException();
	}

	@Override
	public <T> T[] toArray(T[] a) throws UnsupportedOperationException{
		throw new UnsupportedOperationException();
	}

}
